package com.example.mydesignmodule.zhongjiezhe;

/**
 * @author tgw
 * @date 2021/3/9
 * @describe
 *
 * 本来 按键生产者 要知道屏幕大小 他俩必须关联。现在使用 中介者 在一个类中关联
 */
class MainZhongJieZhe extends AbZhongJieZhe{

    private ContactColleage contactColleage;//组装部门
    private ScreenColleage screenColleage;//屏幕
    private AnJianColleage anJianColleage;//屏幕按键型号

    @Override
    public void change(AbColleague abColleague) {

        if (abColleague == anJianColleage){
            handAnjian((AnJianColleage)abColleague);
        }else if (abColleague == screenColleage){
            handScreen((ScreenColleage)abColleague);
        }
    }

    private void handAnjian(AnJianColleage anJianColleage) {
        contactColleage.contact(anJianColleage);
    }

    private void handScreen(ScreenColleage screenColleage1) {
        //按键商要根据屏幕大小 生产合适的按键
        anJianColleage.setScreenSize(screenColleage1.getScreenSize());
    }



    public void setContactColleage(ContactColleage contactColleage) {
        this.contactColleage = contactColleage;
    }


    public void setScreenColleage(ScreenColleage screenColleage) {
        this.screenColleage = screenColleage;
    }


    public void setAnJianColleage(AnJianColleage anJianColleage) {
        this.anJianColleage = anJianColleage;
    }
}
